
/**
 * @author Lukas Koell
 * @author David Medenjak
 * @author Johannes Riedmann
 */
public class PostorderTree extends SortedTree {

    public PostorderTree(StringTree parent, StringTree leftchild, StringTree rightchild, String key) {
        super(parent, leftchild, rightchild, key);
    }
    
    @Override
    public String traverse() {
        return trav(this);
    }
    
    /**
     * recursive postorder traversion
     * @param tree  the tree to be traversed
     * @return the string representation of the traversion
     */
    private String trav(StringTree tree){
        String out = "";
        if(tree != null){
            out = out + trav(tree.leftchild);
            out = out + trav(tree.rightchild);
            out = out + " " + tree.label;
        }
        return out;
    }

    @Override
    public SortedTree getNewInstance() {
        return new PostorderTree(null, null, null, "");
    }

}
